package com.csair.common.utils;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;

public class ActivityUtils {

    private static Bundle getActivityMetaDataBundle(Activity activity) {
        try {
            ActivityInfo info = activity.getPackageManager()
                    .getActivityInfo(activity.getComponentName(),
                            PackageManager.GET_META_DATA);
            return info.metaData;
        } catch (Exception e) {
            LogUtils.printStackTrace(e);
        }
        return null;

    }

    public static String getActivityMetaString(Activity activity, String metaDataName) {
        Bundle bundle = getActivityMetaDataBundle(activity);
        return bundle == null ? "" : bundle.getString(metaDataName);
    }

    /**
     * 判断dialog主题的Activity是否点击了弹框外空白处
     */
    public static boolean isOutOfBounds(Activity context, MotionEvent event) {
        final int x = (int) event.getX();
        final int y = (int) event.getY();
        final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
        final View decorView = context.getWindow().getDecorView();
        return (x < -slop) || (y < -slop) || (x > (decorView.getWidth() + slop)) || (y > (decorView.getHeight() + slop));
    }

}
